<?php 
$pollId = $poll->getId();
$voteIds = $sf_user->getAttribute('voteIds', array());
$isVoted = sizeof($voteIds) ? in_array($pollId, $voteIds) : false;
?>

<form id="pollForm<?php echo $pollId?>" method="POST">

  <input type="hidden" value="<?php echo $pollId?>" name="poll_id" id="poll_id" />
  
  <p><?php echo $poll?></p>  				     
  
  <?php $options = Doctrine::getTable('PollOption')->findByPollId($pollId);?>
  
  <!-- Result -->
  <div id="pollResult<?php echo $pollId?>" style="display:<?php echo $isVoted ? 'block' : 'none'?>;">
   <?php $votes_array = $poll->getVotes();
     foreach ($options as $option)
     {
       echo '<label style="margin:8px;display:block;"><span style="color:#000;">'.$votes_array[$option->getId()]."</span> - ".$option.'</label>';
     }
   ?>
   <a class="right" onclick="togglePoll(<?php echo $pollId?>);" style="text-decoration:underline;"><?php echo ('Үр дүн хаах')?></a>
     <br clear="all">
  </div>
  
  <!-- Choices -->
  <div id="pollChoices<?php echo $pollId?>" style="display:<?php echo $isVoted ? 'none' : 'block'?>;">
     <?php foreach ($options as $option):?>
        <label style="margin:8px;display:block;">
            <input type="radio" name="options[]" align="absmiddle" value="<?php echo $option->getId() ?>" />
            <?php echo $option ?>
        </label>
     <?php endforeach;?>
     
     <!-- Buttons -->
     <?php if(!$isVoted):?>
         <a href="#polls" onclick="submitPollForm(<?php echo $pollId?>);" style="padding:5px 10px;background:#ECE8DA;border:1px solid #D4CCB0;-moz-border-raduis:5px;-webkit-border-raduis:5px;border-raduis:5px;">Санал өгөх</a>
     <?php else:?>
         <p style="margin:10px 0;color:#000;"><?php echo ('Та саналаа өгсөн байна.')?></p>
     <?php endif?>
     
     <a class="right" onclick="togglePoll(<?php echo $pollId?>);" style="text-decoration:underline;"><?php echo ('Үр дүн харах')?></a>
     <br clear="all">
  </div><!--pollChoices-->

</form>